class CreateCategories < ActiveRecord::Migration
    def self.up
        create_table :categories do |t|
            t.integer :order_position, default: 0
			t.string :ancestry
            t.string :created_by, null: false
            t.string :updated_by

            t.timestamps
        end
		
        add_index :categories, :ancestry
		
		Category.create_translation_table! name: :string, description: :text

		create_table :categories_documents, :id => false do |t|
			t.integer :category_id
			t.integer :document_id
		end

		add_index :categories_documents, [:category_id, :document_id], unique: true
    end

    def self.down
        drop_table :categories_documents
		Category.drop_translation_table!
        drop_table :categories
    end
end
